package com.atguigu.flink.chapter10;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.hive.HiveCatalog;

/**
 * @Author lzc
 * @Date 2023/6/30 15:03
 */
public class HiveDemo {
    public static void main(String[] args) {
        System.setProperty("HADOOP_USER_NAME", "atguigu");
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
    
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
    
        HiveCatalog hiveCatalog = new HiveCatalog("hive", "default", "input/");
        // 在当前 session 注册 catalog
        tEnv.registerCatalog("hive", hiveCatalog);
        
        tEnv.executeSql("show catalogs").print();
        
        tEnv.executeSql("use catalog hive");
        tEnv.executeSql("use `default`");
        /*tEnv.executeSql("create table sensor(" +
                            " id string, " +
                            " ts bigint, " +
                            " vc int " +
                            ")with(" +
                            "  'connector' = 'kafka', " +
                            "  'topic' = 's1', " +
                            "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
                            "  'properties.group.id' = 'atguigu', " +
                            "  'scan.startup.mode' = 'latest-offset', " +
                            "  'format' = 'csv' " +
                            ")");*/
        
        
       // tEnv.sqlQuery("select * from abc").execute().print();
        
        tEnv.sqlQuery("select * from sensor").execute().print();
        
        
        
        
    }
}
/*
hive catalog 两个作用:
    1. 持久化表结构
    
    2. 提供了读写 hive api
 */